{% extends 'base/base.html' %}
{% load i18n %}

{% block title %}{% trans '公告管理' %} - {{ block.super }}{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3 mb-0">{% trans '公告管理' %}</h1>
                <a href="{% url 'projects:announcement_create' %}" class="btn btn-primary">
                    <i class="fa fa-plus"></i> {% trans '创建公告' %}
                </a>
            </div>
            
            {% if announcements %}
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">{% trans '公告列表' %}</h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-hover align-middle">
                                <thead class="table-light">
                                    <tr>
                                        <th class="col-2">{% trans '标题' %}</th>
                                        <th class="col-3">{% trans '内容' %}</th>
                                        <th class="col-2">{% trans '目标标签' %}</th>
                                        <th class="col-1">{% trans '创建者' %}</th>
                                        <th class="col-2">{% trans '创建时间' %}</th>
                                        <th class="col-1">{% trans '状态' %}</th>
                                        <th class="col-1">{% trans '操作' %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for announcement in announcements %}
                                        <tr class="position-relative">
                                            <td class="fw-bold">
                                                <div class="text-truncate" style="max-width: 200px;" title="{{ announcement.title }}">
                                                    {{ announcement.title }}
                                                </div>
                                            </td>
                                            <td>
                                                <div class="text-truncate" style="max-width: 250px;" title="{{ announcement.content }}">
                                                    <small class="text-muted">
                                                        {{ announcement.content|striptags|truncatechars:100 }}
                                                    </small>
                                                </div>
                                            </td>
                                            <td>
                                                <div class="d-flex flex-wrap gap-1">
                                                    {% if announcement.tags.all %}
                                                        {% for tag in announcement.tags.all %}
                                                            <span class="badge rounded-pill" style="background-color: {{ tag.color }}; font-size: 0.75em;">
                                                                {{ tag.name }}
                                                            </span>
                                                        {% endfor %}
                                                    {% else %}
                                                        <span class="badge bg-secondary rounded-pill" style="font-size: 0.75em;">
                                                            {% trans '全部项目' %}
                                                        </span>
                                                    {% endif %}
                                                </div>
                                            </td>
                                            <td>
                                                <span class="badge bg-light text-dark border">
                                                    <i class="fa fa-user fa-xs me-1"></i>
                                                    {{ announcement.created_by.username }}
                                                </span>
                                            </td>
                                            <td>
                                                <small class="text-muted">
                                                    <i class="fa fa-clock fa-xs me-1"></i>
                                                    {{ announcement.created_at|date:"m-d H:i" }}
                                                </small>
                                            </td>
                                            <td>
                                                {% if announcement.is_active %}
                                                    <span class="badge bg-success-subtle text-success border border-success rounded-pill">
                                                        <i class="fa fa-check-circle fa-xs me-1"></i>
                                                        {% trans '激活' %}
                                                    </span>
                                                {% else %}
                                                    <span class="badge bg-secondary-subtle text-secondary border border-secondary rounded-pill">
                                                        <i class="fa fa-times-circle fa-xs me-1"></i>
                                                        {% trans '停用' %}
                                                    </span>
                                                {% endif %}
                                            </td>
                                            <td class="td-actions">
                                                <div class="d-flex gap-1">
                                                    <a href="{% url 'projects:announcement_edit' announcement.id %}" 
                                                       class="btn btn-sm btn-outline-primary"
                                                       title="{% trans '编辑公告' %}">
                                                        <i class="fa fa-edit"></i>
                                                        <span class="ms-1">{% trans '编辑' %}</span>
                                                    </a>
                                                    <a href="{% url 'projects:announcement_delete' announcement.id %}" 
                                                       class="btn btn-sm btn-outline-danger"
                                                       title="{% trans '删除公告' %}">
                                                        <i class="fa fa-trash"></i>
                                                        <span class="ms-1">{% trans '删除' %}</span>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="text-center py-5">
                        <i class="fa fa-bullhorn fa-3x text-muted mb-3"></i>
                        <h5 class="text-muted">{% trans '暂无公告' %}</h5>
                        <p class="text-muted">{% trans '点击上方按钮创建第一个公告' %}</p>
                    </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}